import pandas as pd
import matplotlib.pyplot as plt
import geopandas as gpd1
df_geo = pd.read_csv("../../../delete/Demo Health Facilities Geo Data_NHC.csv")
df_geo| Facility Type | Latitude | Longitude | |
|---|---|---|---|
| 0 | Hospital | 5.593051 | 3.697007 |
| 1 | Hospital | 10.017569 | 9.921846 |
| 2 | Hospital | 7.568808 | 11.178651 |
| 3 | Hospital | 11.574567 | 12.594135 |
| 4 | Hospital | 6.093634 | 9.334975 |
| ... | ... | ... | ... |
| 762 | Pharmacy | 11.844224 | 9.831699 |
| 763 | Pharmacy | 8.228317 | 8.502529 |
| 764 | Pharmacy | 8.162100 | 4.821424 |
| 765 | Pharmacy | 7.568452 | 8.388384 |
| 766 | Pharmacy | 4.330299 | 10.229440 |
767 rows × 3 columns
df_geo['Facility Type'].value_counts()Pharmacy 627
Primary Care Center 118
Specialized Healthcare Center 12
Hospital 10
Name: Facility Type, dtype: int64
기관 summary 보는 법
plt.figure(figsize=(8,4))
df_geo['Facility Type'].value_counts().plot(kind='bar')
plt.xlabel("Facility Type")
plt.ylabel("Count")
plt.xticks(rotation=45)
plt.title("Public Health Facility Types")
plt.show()
약국이 제일 많음
primary care center 는 기본 진료 기관?
gdf = gpd.GeoDataFrame(df_geo,geometry=gpd.points_from_xy(df_geo.Longitude, df_geo.Latitude))
gdf.head()| Facility Type | Latitude | Longitude | geometry | |
|---|---|---|---|---|
| 0 | Hospital | 5.593051 | 3.697007 | POINT (3.69701 5.59305) |
| 1 | Hospital | 10.017569 | 9.921846 | POINT (9.92185 10.01757) |
| 2 | Hospital | 7.568808 | 11.178651 | POINT (11.17865 7.56881) |
| 3 | Hospital | 11.574567 | 12.594135 | POINT (12.59413 11.57457) |
| 4 | Hospital | 6.093634 | 9.334975 | POINT (9.33497 6.09363) |
gdf.plot()
gdf.plot(markersize=10,color='blue', alpha=0.5)
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.title('Health Facility Type')
plt.show()
지도 안 깔고 plot으로만 봐보면 이럼
2
##Explore Public Health Facilities Geolocation Demo Dataset using Geopandas Part I
import pandas as pd
import matplotlib.pyplot as plt
import geopandas as gpddf_geo = pd.read_csv("/content/demo_health_facilities_geo_data.csv")
df_geo| Facility Type | Latitude | Longitude | |
|---|---|---|---|
| 0 | Hospital | 5.593051 | 3.697007 |
| 1 | Hospital | 10.017569 | 9.921846 |
| 2 | Hospital | 7.568808 | 11.178651 |
| 3 | Hospital | 11.574567 | 12.594135 |
| 4 | Hospital | 6.093634 | 9.334975 |
| ... | ... | ... | ... |
| 762 | Pharmacy | 11.844224 | 9.831699 |
| 763 | Pharmacy | 8.228317 | 8.502529 |
| 764 | Pharmacy | 8.162100 | 4.821424 |
| 765 | Pharmacy | 7.568452 | 8.388384 |
| 766 | Pharmacy | 4.330299 | 10.229440 |
767 rows × 3 columns
df_geo['Facility Type'].value_counts()Pharmacy 627
Primary Care Center 118
Specialized Healthcare Center 12
Hospital 10
Name: Facility Type, dtype: int64
plt.figure(figsize=(8,4))
df_geo['Facility Type'].value_counts().plot(kind='bar')
plt.xlabel("Facility Type")
plt.ylabel("Count")
plt.xticks(rotation=45)
plt.title("Public Health Facility Types")
plt.show()
gdf = gpd.GeoDataFrame(df_geo,geometry=gpd.points_from_xy(df_geo.Longitude, df_geo.Latitude))
gdf| Facility Type | Latitude | Longitude | geometry | |
|---|---|---|---|---|
| 0 | Hospital | 5.593051 | 3.697007 | POINT (3.69701 5.59305) |
| 1 | Hospital | 10.017569 | 9.921846 | POINT (9.92185 10.01757) |
| 2 | Hospital | 7.568808 | 11.178651 | POINT (11.17865 7.56881) |
| 3 | Hospital | 11.574567 | 12.594135 | POINT (12.59413 11.57457) |
| 4 | Hospital | 6.093634 | 9.334975 | POINT (9.33497 6.09363) |
| ... | ... | ... | ... | ... |
| 762 | Pharmacy | 11.844224 | 9.831699 | POINT (9.83170 11.84422) |
| 763 | Pharmacy | 8.228317 | 8.502529 | POINT (8.50253 8.22832) |
| 764 | Pharmacy | 8.162100 | 4.821424 | POINT (4.82142 8.16210) |
| 765 | Pharmacy | 7.568452 | 8.388384 | POINT (8.38838 7.56845) |
| 766 | Pharmacy | 4.330299 | 10.229440 | POINT (10.22944 4.33030) |
767 rows × 4 columns
gdf.plot()
gdf.plot(markersize=10,color='blue', alpha=0.5)
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.title('Health Facility Type')
plt.show()
##Explore Public Health Facilities Geolocation Demo Dataset using Geopandas Part II
buffers = gdf.copy()
buffers['geometry'] = gdf.buffer(0.10)buffers.plot()
buffers.plot(color='blue', edgecolor='k', alpha=0.8)
gdf.plot(color='blue', markersize=10, label="Geopoints")
buffers.plot(edgecolor="red", linewidth=2,label="Buffers", alpha=0.8)
plt.title("Geopoints and Buffer")
plt.show()

fig, ax = plt.subplots(figsize=(10,8))
gdf.plot(ax=ax,color='blue', markersize=4,label="Geopoints")
buffers.plot(ax=ax, edgecolor='red', linewidth=1,label='Buffers')
#plt.legend()
plt.title("Geopoints and Buffer")
plt.show()
3
import pandas as pd
import foliumdf_geo = pd.read_csv('/content/demo_health_facilities_geo_data.csv')
df_geo| Facility Type | Latitude | Longitude | |
|---|---|---|---|
| 0 | Hospital | 5.593051 | 3.697007 |
| 1 | Hospital | 10.017569 | 9.921846 |
| 2 | Hospital | 7.568808 | 11.178651 |
| 3 | Hospital | 11.574567 | 12.594135 |
| 4 | Hospital | 6.093634 | 9.334975 |
| ... | ... | ... | ... |
| 762 | Pharmacy | 11.844224 | 9.831699 |
| 763 | Pharmacy | 8.228317 | 8.502529 |
| 764 | Pharmacy | 8.162100 | 4.821424 |
| 765 | Pharmacy | 7.568452 | 8.388384 |
| 766 | Pharmacy | 4.330299 | 10.229440 |
767 rows × 3 columns
df_geo['Facility Type'].nunique()4
df_geo['Facility Type'].unique()array(['Hospital', 'Primary Care Center', 'Specialized Healthcare Center',
'Pharmacy'], dtype=object)
m = folium.Map(location=[df_geo['Latitude'].iloc[0], df_geo['Longitude'][0]])
for index,row in df_geo.iterrows():
folium.Marker([row['Latitude'],row['Longitude']], popup=row['Facility Type']).add_to(m)
mfacility_color_mapping = {'Hospital':'red', 'Primary Care Center':'blue','Specialized Healthcare Center':'green','Pharmacy':'purple'}m = folium.Map(location=[df_geo['Latitude'].iloc[0], df_geo['Longitude'][0]])
for index, row in df_geo.iterrows():
facility_type = row['Facility Type']
if facility_type in facility_color_mapping:
color = facility_color_mapping[facility_type]
else:
color = 'gray'
folium.Marker(location=[row['Latitude'],row['Longitude']],popup=row['Facility Type'], icon=folium.Icon(color=color)).add_to(m)m4
##Interactive Map for Public Health Facilities Geolocation Demo Dataset using Folium Part I
import pandas as pd
import foliumdf_geo = pd.read_csv('/content/demo_health_facilities_geo_data.csv')
df_geo| Facility Type | Latitude | Longitude | |
|---|---|---|---|
| 0 | Hospital | 5.593051 | 3.697007 |
| 1 | Hospital | 10.017569 | 9.921846 |
| 2 | Hospital | 7.568808 | 11.178651 |
| 3 | Hospital | 11.574567 | 12.594135 |
| 4 | Hospital | 6.093634 | 9.334975 |
| ... | ... | ... | ... |
| 762 | Pharmacy | 11.844224 | 9.831699 |
| 763 | Pharmacy | 8.228317 | 8.502529 |
| 764 | Pharmacy | 8.162100 | 4.821424 |
| 765 | Pharmacy | 7.568452 | 8.388384 |
| 766 | Pharmacy | 4.330299 | 10.229440 |
767 rows × 3 columns
df_geo['Facility Type'].nunique()4
df_geo['Facility Type'].unique()array(['Hospital', 'Primary Care Center', 'Specialized Healthcare Center',
'Pharmacy'], dtype=object)
m = folium.Map(location=[df_geo['Latitude'].iloc[0], df_geo['Longitude'][0]])
for index,row in df_geo.iterrows():
folium.Marker([row['Latitude'],row['Longitude']], popup=row['Facility Type']).add_to(m)
mfacility_color_mapping = {'Hospital':'red', 'Primary Care Center':'blue','Specialized Healthcare Center':'green','Pharmacy':'purple'}m = folium.Map(location=[df_geo['Latitude'].iloc[0], df_geo['Longitude'][0]])
for index, row in df_geo.iterrows():
facility_type = row['Facility Type']
if facility_type in facility_color_mapping:
color = facility_color_mapping[facility_type]
else:
color = 'gray'
folium.Marker(location=[row['Latitude'],row['Longitude']],popup=row['Facility Type'], icon=folium.Icon(color=color)).add_to(m)m##Interactive Map for Public Health Facilities Geolocation Demo Dataset using Folium Part II
m = folium.Map(location=[df_geo['Latitude'].iloc[0], df_geo['Longitude'].iloc[0]])
facility_types_to_visualize = ['Hospital']
filtered_df = df_geo[df_geo['Facility Type'].isin(facility_types_to_visualize)]
for index, row in filtered_df.iterrows():
facility_type = row['Facility Type']
color = facility_color_mapping.get(facility_type,'gray')
folium.Marker(location=[row['Latitude'],row['Longitude']], popup=row['Facility Type'], icon=folium.Icon(color=color)).add_to(m)
m5
##Interactive Map for Public Health Facilities Geolocation Demo Dataset using Folium Part I
import pandas as pd
import foliumdf_geo = pd.read_csv('/content/demo_health_facilities_geo_data.csv')
df_geo| Facility Type | Latitude | Longitude | |
|---|---|---|---|
| 0 | Hospital | 5.593051 | 3.697007 |
| 1 | Hospital | 10.017569 | 9.921846 |
| 2 | Hospital | 7.568808 | 11.178651 |
| 3 | Hospital | 11.574567 | 12.594135 |
| 4 | Hospital | 6.093634 | 9.334975 |
| ... | ... | ... | ... |
| 762 | Pharmacy | 11.844224 | 9.831699 |
| 763 | Pharmacy | 8.228317 | 8.502529 |
| 764 | Pharmacy | 8.162100 | 4.821424 |
| 765 | Pharmacy | 7.568452 | 8.388384 |
| 766 | Pharmacy | 4.330299 | 10.229440 |
767 rows × 3 columns
df_geo['Facility Type'].nunique()4
df_geo['Facility Type'].unique()array(['Hospital', 'Primary Care Center', 'Specialized Healthcare Center',
'Pharmacy'], dtype=object)
m = folium.Map(location=[df_geo['Latitude'].iloc[0], df_geo['Longitude'][0]])
for index,row in df_geo.iterrows():
folium.Marker([row['Latitude'],row['Longitude']], popup=row['Facility Type']).add_to(m)
mfacility_color_mapping = {'Hospital':'red', 'Primary Care Center':'blue','Specialized Healthcare Center':'green','Pharmacy':'purple'}m = folium.Map(location=[df_geo['Latitude'].iloc[0], df_geo['Longitude'][0]])
for index, row in df_geo.iterrows():
facility_type = row['Facility Type']
if facility_type in facility_color_mapping:
color = facility_color_mapping[facility_type]
else:
color = 'gray'
folium.Marker(location=[row['Latitude'],row['Longitude']],popup=row['Facility Type'], icon=folium.Icon(color=color)).add_to(m)m##Interactive Map for Public Health Facilities Geolocation Demo Dataset using Folium Part II
m = folium.Map(location=[df_geo['Latitude'].iloc[0], df_geo['Longitude'].iloc[0]])
facility_types_to_visualize = ['Hospital']
filtered_df = df_geo[df_geo['Facility Type'].isin(facility_types_to_visualize)]
for index, row in filtered_df.iterrows():
facility_type = row['Facility Type']
color = facility_color_mapping.get(facility_type,'gray')
folium.Marker(location=[row['Latitude'],row['Longitude']], popup=row['Facility Type'], icon=folium.Icon(color=color)).add_to(m)
m##Interactive Map for Public Health Facilities Geolocation Demo Dataset using Folium Part III
from folium.plugins import HeatMapm = folium.Map(location=[df_geo['Latitude'].iloc[0],df_geo['Longitude'].iloc[0]])heat_data = [[row['Latitude'], row['Longitude']] for index, row in df_geo.iterrows()]
HeatMap(heat_data).add_to(m)
mm.save('facility_heatmap.html')from folium.plugins import MarkerClusterm = folium.Map(location=[df_geo['Latitude'].iloc[0],df_geo['Longitude'].iloc[0]])marker_cluster = MarkerCluster()for index, row in df_geo.iterrows():
marker = folium.Marker([row['Latitude'],row['Longitude']], popup=row['Facility Type'])
marker.add_to(marker_cluster)
marker_cluster.add_to(m)
m